<?php
/**
* @author Bimal Poudel
* @copyright since 2006, Bimal Poudel
* @package Smarty Framework
* @support http://www.odesk.com/users/~~dd91d11caed0cdce
* @contact http://www.sanjaal.com
* @company Sanjaal Corps
*/

# Created on: 2012-04-08 12:50:53 506

/**
* Quickly flags a single field in the tables.
* Fields on which we can act upon are pre-defined in the class file.
*/

$users = new users();
$user_id = $variable->get('id', 'integer', 0);
$code = $variable->get('code', 'string', '');
$flag = $variable->get('flag', 'string', '');

# Assumes, ID always, in the GET parameter
if($user_id!=0 && $code!='' && $flag!='')
{
	$data = $members->details($member_id, $code);
	if(!$data)
	{
		$messenger = new messenger('error', 'Invalid data.');
		stopper::url(url::last_page('users-list.php?context=invaliddata'));
	}
	if(empty($data['code']) || $data['code']!=$code)
	{
		$messenger = new messenger('warning', 'Verification code is invalid.');
		stopper::url(url::last_page('users-list.php?context=invalidcode'));
	}

	if($users->flag_field($user_id, $code, $flag))
	{
		$messenger = new messenger('notice', 'The record has been successfully flagged.');
		
		# The list from where the flag was applied will appear back with pagination.
		headers::back(url::last_page('users-list.php?flagging=successful'));
	}
	else
	{
		$messenger = new messenger('error', 'The record has NOT been flagged yet. Such flag does not exist.');
		stopper::url(url::last_page('users-list.php?context=flagging'));
	}
}
else
{
	stopper::url('users-direct-access-error.php?context=flagging');
}
?>